package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * 本安信号转换器（电压盒、交直流回路）心跳数据
 */
public class DianYaHeHeartBean {

    public int signal ; //信号值
    public int power; //电量值
    public int type = -1;
    public int index = -1;
    public ComBean comBean ;
    public long time ; //数据包时间

    public DianYaHeHeartBean() {

    }

    public DianYaHeHeartBean(ComBean comBean ) {
        caculate(comBean.recData);
        time = comBean.recTime;
        this.comBean = comBean;
    }

    public DianYaHeHeartBean(byte[] recData) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public DianYaHeHeartBean caculate(ComBean comBean){
        time = comBean.recTime;
        this.comBean = comBean;
        return caculate(comBean.recData);
    }

    public DianYaHeHeartBean caculate(byte[] buffer) {
        signal = MyFunc.getSignal(buffer[16]); //测试信号
        power = MyFunc.getPower(buffer[14], buffer[15]);//电量
        type = buffer[9];
        index = buffer[10];
        return this;
    }

    public void  test(){
        time = System.currentTimeMillis();
        power = 300 + myRandom.nextInt(120);
        signal = 200;
    }
}
